-- Leviathan (c) v.v.balashoff
local Class = require('leviathan/Class')

local SliderOffsetSystem = Class:derive('UISliderOffsetSystem')

function SliderOffsetSystem:new(domain)
    self.name = 'SliderOffsetSystem'
    self.domain = domain
end

function SliderOffsetSystem:update(dt)
    local comps = self.domain.components['SliderOffset']
    if not comps then
        return
    end
    for i = 1, #comps do
        c = comps[i]
        if c.enabled then
            if c.id == 'SliderOffsetComponent' and c.target then
                local yOld = c.target.y
                local value = c.slider.value
                local v = c.y + c.h * value
                c.target.y = v
                if not (math.floor(yOld) == math.floor(v)) then
                    self.domain.changed = true
                end
            end
        end
    end
end

return SliderOffsetSystem
